add test skeleton for OCC::FolderStatusModel
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Tue, 11 Feb 2025 09:17:16 +0000 (10:17 +0100)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Wed, 12 Feb 2025 08:49:09 +0000 (09:49 +0100)
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/gui/folderman.h
test/CMakeLists.txt
test/syncenginetestutils.h
test/testfolderstatusmodel.cpp [new file with mode: 0644]

index 27a231adc9bede3a26fe3d85614daf086d7e531e..8bb71b7325f9141eb2a57f97dd1f937e74302e9e 100644 (file)
@@ -29,6 +29,7 @@
 class TestFolderMan;
 class TestCfApiShellExtensionsIPC;
 class TestShareModel;
+class TestFolderStatusModel;
 class ShareTestHelper;
 class EndToEndTestHelper;
 class TestSyncConflictsModel;
@@ -413,6 +414,7 @@ private:
     friend class ::TestCfApiShellExtensionsIPC;
     friend class ::ShareTestHelper;
     friend class ::EndToEndTestHelper;
+    friend class ::TestFolderStatusModel;
 };
 
 } // namespace OCC
index 75eaaf7049e2619d6129bfc63d699c376db3acec..ada0d64c58cc582e8415d9e4beae7101ffbe8d14 100644 (file)
@@ -95,6 +95,8 @@ nextcloud_add_test(SyncConflictsModel)
 nextcloud_add_test(DateFieldBackend)
 nextcloud_add_test(ClientStatusReporting)
 
+nextcloud_add_test(FolderStatusModel)
+
 target_link_libraries(SecureFileDropTest PRIVATE Nextcloud::sync)
 configure_file(fake2eelocksucceeded.json "${PROJECT_BINARY_DIR}/bin/fake2eelocksucceeded.json" COPYONLY)
 configure_file(fakefiledrope2eefoldermetadata.json "${PROJECT_BINARY_DIR}/bin/fakefiledrope2eefoldermetadata.json" COPYONLY)
index 9a288d97dd7ce4eae1bc842707d7478538f50510..b188a2d00a8aa4ee8763d03aceb2481d52c00ace 100644 (file)
@@ -562,6 +562,7 @@ public:
     [[nodiscard]] OCC::AccountPtr account() const { return _account; }
     [[nodiscard]] OCC::SyncEngine &syncEngine() const { return *_syncEngine; }
     [[nodiscard]] OCC::SyncJournalDb &syncJournal() const { return *_journalDb; }
+    [[nodiscard]] FakeQNAM* networkAccessManager() const { return _fakeQnam; }
 
     FileModifier &localModifier() { return _localModifier; }
     FileInfo &remoteModifier() { return _fakeQnam->currentRemoteState(); }
diff --git a/test/testfolderstatusmodel.cpp b/test/testfolderstatusmodel.cpp
new file mode 100644 (file)
index 0000000..440dcf5
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) by Matthieu Gallien <matthieu.gallien@nextcloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include <QtTest>
+#include <QStandardPaths>
+#include <QAbstractItemModelTester>
+
+#include "accountstate.h"
+#include "folderman.h"
+#include "folderstatusmodel.h"
+#include "logger.h"
+#include "syncenginetestutils.h"
+#include "testhelper.h"
+
+using namespace OCC;
+using namespace OCC::Utility;
+
+class TestFolderStatusModel : public QObject
+{
+    Q_OBJECT
+
+    std::unique_ptr<FolderMan> _folderMan;
+
+public:
+
+private Q_SLOTS:
+    void initTestCase()
+    {
+        Logger::instance()->setLogFlush(true);
+        Logger::instance()->setLogDebug(true);
+
+        QStandardPaths::setTestModeEnabled(true);
+
+        _folderMan.reset(new FolderMan{});
+    }
+
+    void startModel()
+    {
+        FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
+
+        const auto account = fakeFolder.account();
+        const auto capabilities = QVariantMap {
+                                              {QStringLiteral("end-to-end-encryption"), QVariantMap {
+                                                                                            {QStringLiteral("enabled"), true},
+                                                                                            {QStringLiteral("api-version"), QString::number(2.0)},
+                                                                                            }},
+                                              };
+        account->setCapabilities(capabilities);
+        account->setCredentials(new FakeCredentials{fakeFolder.networkAccessManager()});
+        account->setUrl(QUrl(("owncloud://somehost/owncloud")));
+        auto accountState = FakeAccountState(account);
+        QVERIFY(accountState.isConnected());
+
+        auto folderDef = folderDefinition(fakeFolder.localPath());
+        folderDef.targetPath = "";
+        const auto folder = FolderMan::instance()->addFolder(&accountState, folderDef);
+        QVERIFY(folder);
+
+        FolderStatusModel test;
+        test.setAccountState(&accountState);
+
+        QSKIP("Initial test implementation is known to be broken");
+        QAbstractItemModelTester modeltester(&test);
+
+        test.fetchMore({});
+    }
+};
+
+QTEST_MAIN(TestFolderStatusModel)
+#include "testfolderstatusmodel.moc"